aabd9d
@@ -368,12 +368,13 @@
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
 		}
 
 		Class<?> type = typeInformation.getType();
+		E entity = null;
 
 		try {
 
 			write.lock();
 
-			final E entity = createPersistentEntity(typeInformation);
+			entity = createPersistentEntity(typeInformation);
 
 			// Eagerly cache the entity as we might have to find it during recursive lookups.
 			persistentEntities.put(typeInformation, Optional.of(entity));
@@ -402,18 +403,18 @@
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
 				throw e;
 			}
 
-			// Inform listeners
-			if (null != applicationEventPublisher) {
-				applicationEventPublisher.publishEvent(new MappingContextEvent<>(this, entity));
-			}
-
-			return Optional.of(entity);
-
 		} catch (BeansException e) {
 			throw new MappingException(e.getMessage(), e);
 		} finally {
 			write.unlock();
 		}
+
+		// Inform listeners
+		if (applicationEventPublisher != null && entity != null) {
+			applicationEventPublisher.publishEvent(new MappingContextEvent<>(this, entity));
+		}
+
+		return Optional.of(entity);
 	}
 
 	/*
